<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改菜单')" />
</head>

<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-menu-edit" th:object="${menu}">
			<input name="smId"   type="hidden" th:field="*{smId}"   />
			<input id="treeId" name="smPid" type="hidden" th:field="*{smPid}" />
			<div class="form-group">
				<label class="col-sm-3 control-label">上级菜单：</label>
				<div class="col-sm-8">
				    <div class="input-group">
						<input readonly="true" class="form-control" type="text" th:value="${pmenu == null ? '主目录' : pmenu.smTitle}">
				    </div>
				</div>
			</div>
<!--			<div class="form-group">-->
<!--				<label class="col-sm-3 control-label is-required">菜单类型：</label>-->
<!--				<div class="col-sm-8">-->
<!--					<label class="radio-box"> <input type="radio" th:field="*{menuType}" name="menuType" value="M" /> 目录 </label> -->
<!--					<label class="radio-box"> <input type="radio" th:field="*{menuType}" name="menuType" value="C" /> 菜单 </label> -->
<!--					<label class="radio-box"> <input type="radio" th:field="*{menuType}" name="menuType" value="F" /> 按钮 </label>-->
<!--				</div>-->
<!--			</div>-->
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">菜单标题：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="smTitle" id="smTitle" th:field="*{smTitle}" required>
				</div>
			</div>

			<div class="form-group" th:if="*{smId < 1000}">
				<label class="col-sm-3 control-label">请求地址：</label>
				<div class="col-sm-8">
					<input id="smUrl" name="smUrl" class="form-control" type="text" th:field="*{smUrl}">
				</div>
			</div>

			<div class="form-group" th:if="*{smId < 1000}">
				<label class="col-sm-3 control-label">打开方式：</label>
				<div class="col-sm-8">
					<select id="smType" name="smType" class="form-control m-b">
	                    <option value="1" th:field="*{smType}">页签</option>
	                    <option value="2" th:selected="*{smType == 2}">新窗口</option>
	                </select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">权限标识：</label>
				<div class="col-sm-8">
					<input id="perms" name="perms" class="form-control" type="text" th:field="*{perms}">
				    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 控制器中定义的权限标识，如：@RequiresPermissions("")</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">显示排序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="smSort" th:field="*{smSort}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">图标：</label>
				<div class="col-sm-8">
					<input id="smIcon" name="smIcon" class="form-control" type="text" placeholder="选择图标" th:field="*{smIcon}">
                    <div class="ms-parent" style="width: 100%;">
                        <div class="icon-drop animated flipInX" style="display: none;max-height:200px;overflow-y:auto">
                            <div data-th-include="system/menu/icon"></div>
                        </div>
                    </div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">菜单状态：</label>
				<div class="col-sm-3">
					<div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
						<input type="radio" th:id="${dict.dictCode}" name="smStatus" th:value="${dict.dictValue}" th:field="*{smStatus}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
<!--				<label class="col-sm-2 control-label is-refresh" title="打开菜单选项卡是否刷新页面">是否刷新：<i class="fa fa-question-circle-o"></i></label>-->
<!--				<div class="col-sm-3 is-refresh">-->
<!--				    <div class="radio-box">-->
<!--						<input type="radio" id="refresh-no" name="isRefresh" value="1" th:field="*{isRefresh}">-->
<!--						<label for="refresh-no">否</label>-->
<!--					</div>-->
<!--					<div class="radio-box">-->
<!--						<input type="radio" id="refresh-yes" name="isRefresh" value="0" th:field="*{isRefresh}">-->
<!--						<label for="refresh-yes">是</label>-->
<!--					</div>-->
<!--				</div>-->
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	 <script>
        var prefix = ctx + "system/menu";

        $(function() {
            var menuType = $('input[name="menuType"]:checked').val();
            menuVisible(menuType);
        });

        $("#form-menu-edit").validate({
        	onkeyup: false,
        	rules:{
        		menuType:{
        			required:true,
        		},
        		smTitle:{
        			remote: {
                        url: prefix + "/checkMenuNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	"smId": function() {
                                return $("#smId").val();
                            },
                            "smPid": function() {
		                		return $("input[name='smPid']").val();
		                    },
                			"smTitle": function() {
                                return $.common.trim($("#smTitle").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        		smSort:{
        			digits:true
        		},
        	},
        	messages: {
                "smTitle": {
                    remote: "菜单已经存在"
                }
            },
            focusCleanup: true
        });
        
        function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-menu-edit').serialize());
	        }
	    }

        $(function() {
            $("input[name='smIcon']").focus(function() {
                $(".icon-drop").show();
            });
            $("#form-menu-edit").click(function(event) {
                var obj = event.srcElement || event.target;
                if (!$(obj).is("input[name='smIcon']")) {
                    $(".icon-drop").hide();
                }
            });
            $(".icon-drop").find(".ico-list i").on("click",
            function() {
                $('#smIcon').val($(this).attr('class'));
            });
            $('input').on('ifChecked',
            function(event) {
                var menuType = $(event.target).val();
                menuVisible(menuType);
            });
        });

        function menuVisible(menuType) {
            if (menuType == "M") {
                $("#smUrl").parents(".form-group").hide();
                $("#perms").parents(".form-group").hide();
                $("#smIcon").parents(".form-group").show();
                $("#smType").parents(".form-group").hide();
                $("input[name='smStatus']").parents(".form-group").show();
                $(".is-refresh").hide();
            } else if (menuType == "C") {
                $("#smUrl").parents(".form-group").show();
                $("#perms").parents(".form-group").show();
                $("#smIcon").parents(".form-group").show();
                $("#smType").parents(".form-group").show();
                $("input[name='smStatus']").parents(".form-group").show();
                $(".is-refresh").show();
            } else if (menuType == "F") {
                $("#smUrl").parents(".form-group").hide();
                $("#perms").parents(".form-group").show();
                $("#smIcon").parents(".form-group").hide();
                $("#smType").parents(".form-group").hide();
                $("input[name='smStatus']").parents(".form-group").hide();
                $(".is-refresh").hide();
            }
        }

        /*菜单管理-修改-选择菜单树*/
        function selectMenuTree() {
        	var menuId = $("#treeId").val();
        	if(menuId > 0) {
        		var url = prefix + "/selectMenuTree/" + menuId;
        		$.modal.open("选择菜单", url, '380', '380');
        	} else {
        		$.modal.alertError("主菜单不能选择");
        	}
        }
        
        function selectMenuTree() {
        	var menuId = $("#treeId").val();
        	if(menuId > 0) {
        		var url = prefix + "/selectMenuTree/" + menuId;
        		var options = {
       				title: '菜单选择',
       				width: "380",
       				url: url,
       				callBack: doSubmit
       			};
       			$.modal.openOptions(options);
        	} else {
        		$.modal.alertError("主菜单不能选择");
        	}
		}
		
		function doSubmit(index, layero){
			var body = layer.getChildFrame('body', index);
   			$("#treeId").val(body.find('#treeId').val());
   			$("#treeName").val(body.find('#treeName').val());
   			layer.close(index);
		}
    </script>
</body>
</html>
